package inet.app.controller.parser;


import inet.app.model.object.Chat_Item;

import java.util.ArrayList;

public class Parser_ChatBox {

	
	private String NAME = "CHAT_RESP";
	private ArrayList<Chat_Item> list = new ArrayList<Chat_Item>();
	
	public Parser_ChatBox() {
	}
	
	public ArrayList<Chat_Item> getList(String json) {
		String chatuser="",chatcontent="",chattime="";
		String[] data = json.split("\\|\\|\r\n");
		System.out.println("DATA SIZE " + data.length);
		
		String[] item_first = data[0].split("\\|");
		String name = item_first[0];
		String status = item_first[1];
		
		if (status.equals("0") && name.equals(NAME)) {
			System.out.println("CHAY VAO PAR 1");
			int i = 0;
			Chat_Item item;
			String strResult[] ;
			for (i = 0; i < data.length; i++) {
				strResult = data[i].split("\\|");
				chattime = strResult[2];
				chatuser = strResult[3];
				chatcontent = strResult[4];
				item = new Chat_Item(chattime,chatuser,chatcontent);
				list.add(item);
			}
			return list;
			
		} else{
			return null;
		}
	}

}
